<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="paryorder-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
			<view class="" slot="top" >
				<u-navbar :border-bottom="false" :background="{background:'#F8F8F8'}" title="历史售后" :title-size="36" :title-bold="true" :title-color="textColor" >
					
				</u-navbar>
			</view>
			<view class="u-p-35">
				
				<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
				<view class="list-item" v-for="(item, index) in dataList" :key="index" @click="$mRouter.push({ route: '/pages/purchase/shouhou/xiangqing?id=' + item.id })">
					<view class="item-header">
						<view class="left u-flex">
							<view class="u-flex u-row-between u-m-r-10">
								<view v-if="item.afterSalesType == 1" class="u-font-24 theme-color theme-box">
									退款
								</view>
								<view v-else class="u-font-24 theme-color theme-box">
									退货
								</view>
							</view>
							<text :style="{fontSize: '26rpx'}">{{item.statusDescription}}</text>
						</view>
						<view class="u-flex" v-if="item.createdTime">
							<text class="u-m-r-10" :style="{fontSize: '24rpx'}">{{$fui.dateFormatter(item.createdTime, 'y-m-d h:i')}}</text>
							<u-icon name="arrow-right" color="#999" size="28rpx"></u-icon>
						</view>
					</view>
					<view class="item-content" v-for="info in item.items" :key="info.itemId">
						<img :src="info.itemResourceUrl" alt="" style="width: 110rpx;height:110rpx;border-radius: 10rpx;">
						<view class="u-flex-col u-row-around u-m-l-20" style="flex-grow: 1;">
							<view>{{ info.itemName }}</view>
							<view class="u-flex u-row-between">
								<view class="u-flex u-row-left">
									<view class="grey-box">
										{{ info.specification }}
									</view>
								</view>
								<view  class="grey-box">
									x{{ info.quantity }}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</z-paging>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				firstLoaded: false,
				paymentStatus:['待审核','生效中','已拒绝','已过期','草稿','保存'],
				tradeId:'',
			}
		},
		onLoad(option) {
			this.tradeId = option.id;
		},
		methods: {
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
					tradeId:this.tradeId
				}
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				const res = await this.$newHttp.get('api/v1.3/AfterSalesOrder/GetByTradeId', { params: params } );
				uni.hideLoading({
					title: 'loading...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data);
					this.firstLoaded = true;
					
				}else{
					this.$refs.paging.complete(false);
				}
			},
			itemClick(item) {
				if(item.paymentStatus != 5){
					this.$mRouter.push({
						route: '/pages/purchase/mySale/signDetails?data='+JSON.stringify(item),
					})
				}else{
					this.$u.toast('该付款单已关闭')
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.paryorder-content {
		height: 100%;
	}
	.list-item {
		background-color: #FFFFFF;
		padding:35rpx 35rpx 10rpx 35rpx;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
		.theme-box {
			border: 1rpx solid $theme-color;
			padding: 5rpx 16rpx;
			border-radius: 5rpx;
		}
		.item-header {
			display: flex;
			justify-content: space-between;
			font-size: 24rpx;
			font-weight: bold;
			// line-height: 81rpx;
			// height: 81rpx;
			padding: 0rpx 0 30rpx;
			.left {
				font-size: 30rpx;
			}
		}
		.item-content {
			display: flex;
			justify-content: flex-start;
			margin-bottom: 30rpx;
			.center {
				margin-left: 20rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
			}
		}
		.item-footer {
			padding: 20rpx 0;
			min-height: 110rpx;
		}
	}


</style>
